
-- $Id: FyLooter.lua 41 2009-03-25 03:52:41Z Fylgjas $

-- ========================================================================= --
-- Copyright © 2009 Thomas ROBERT                                            --
-- ========================================================================= --
-- This file is part of FyLooter.                                            --
--                                                                           --
-- FyLooter is free software: you can redistribute it and/or modify it under --
-- the terms of the GNU General Public License as published by the Free      --
-- Software Foundation, either version 3 of the License, or (at your option) --
-- any later version.                                                        --
--                                                                           --
-- FyLooter is distributed in the hope that it will be useful, but WITHOUT   --
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     --
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for  --
-- more details.                                                             --
--                                                                           --
-- You should have received a copy of the GNU General Public License along   --
-- with FyLooter. If not, see <http://www.gnu.org/licenses/>.                --
-- ========================================================================= --

FyLooter = LibStub("AceAddon-3.0"):NewAddon("FyLooter", "AceConsole-3.0",
                                                        "AceEvent-3.0",
                                                        "AceComm-3.0",
                                                        "AceSerializer-3.0");

-- ========================================================================= --

FyLooter.DEBUG = true;
FyLooter.ADMIN = true;

-- ------------------------------------------------------------------------- --

FyLooter.Status = {
  ["NEED"]  = 1,
  ["GREED"] = 2,
  ["PASS"]  = 3,
};

-- ------------------------------------------------------------------------- --

FyLooter.Data  = {};
FyLooter.Core  = {};
FyLooter.Model = {};
FyLooter.Gui   = {};

-- ========================================================================= --

local defaults = {
  ["char"] = {
    ["settings"] = {
      ["mmb"] = { 0, -80 },    -- MinimapButton position
    },
    ["timestamp"] = 0,
    ["players"] = {},
    ["candidates"] = {},
  }
};

-- ========================================================================= --

function FyLooter:OnInitialize()
  FyLooter:Debug("FyLooter:OnInitialize()");
  
  local db = LibStub("AceDB-3.0"):New("FyLooter_DB", defaults);

  FyLooter.Data = db.char;

  FyLooter.Gui:SetupWidgets();
end

-- ------------------------------------------------------------------------- --

function FyLooter:OnEnable()
  self:RegisterEvent("OPEN_MASTER_LOOT_LIST", self.Core.OnMasterLootListOpened);

--  self:RegisterComm("FLer_VersionCheck", self.Core.OnVersionCheck);
--  self:RegisterComm("FLer_NewVersion", self.Core.OnNewVersion);
  self:RegisterComm("FLer_PlayersCommit", self.Core.OnPlayersCommit);
  self:RegisterComm("FLer_PlayersCheckout", self.Core.OnPlayersCheckout);
  self:RegisterComm("FLer_RollRequest", self.Core.OnRollRequest);
  self:RegisterComm("FLer_RollAnswer", self.Core.OnRollAnswer);
  self:RegisterComm("FLer_LootCleared", self.Core.OnLootCleared);

--  FyLooter.Core:CheckVersion();
  FyLooter.Core:CheckoutPlayers();
end

-- ------------------------------------------------------------------------- --

function FyLooter:OnDisable()
  self:UnregisterAllEvents();
  self:UnregisterAllComm();
end

-- ========================================================================= --

function FyLooter:Delete(object)
  if (object) then
    if (type(object) == "table") then
      for k in pairs(object) do
	    	self:Delete(object[k]);
      end
    end

    object = nil;
  end
end

-- ------------------------------------------------------------------------- --

function FyLooter:Clone(object)
  local clone = nil;

  if (type(object) == "table") then
    clone = {};
    for k, v in pairs(object) do
      clone[FyLooter:Clone(k)] = FyLooter:Clone(v);
    end
  else
    clone = object;
  end

  return clone;
end

-- ------------------------------------------------------------------------- --

function FyLooter:Debug(msg)
	if (FyLooter.DEBUG == true) then
		DEFAULT_CHAT_FRAME:AddMessage("DEBUG - FyLooter: " .. msg, 1, 0, 0);
	end
end

-- ========================================================================= --


